package javango.db;

import com.google.inject.Inject;
import com.google.inject.Injector;

public abstract class AbstractManagers implements Managers {

	Injector injector;
	
	@Inject
	public AbstractManagers(Injector injector) {
		super();
		this.injector = injector;
	}

	final public <T> Manager<T> forClass(Class model) {
		ManagedBy by = (ManagedBy)model.getAnnotation(ManagedBy.class);
		if (by == null) {
			return getForClass(model);
		}
		
		return (Manager<T>)injector.getInstance(by.value());
	}

	abstract protected <T> Manager<T> getForClass(Class model);
}
